﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
    <link href="~/Content/Css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="~/Content/Css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="~/Content/Css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <link href="~/Content/Css/animate.css" rel="stylesheet">
    <link href="~/Content/Css/style.css?v=4.1.0" rel="stylesheet">
    <link href="~/Content/Css/plugins/jsTree/style.min.css" rel="stylesheet">

    <style>
        .ibox-content {
            padding: 15px 20px 0px 20px;
        }

        .treeDiv {
            overflow-y: auto;
            overflow-x: auto;
        }
    </style>
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>城市列表</h5>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <div class="row row-lg">

                            <div class="col-sm-6">
                                <div class="btn-group">
                                    @*<button id="insertTreeBtn" type="button" class="btn btn-outline btn-default">
                                            <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>
                                        </button>
                                        <button id="editTreeBtn" type="button" class="btn btn-outline btn-default">
                                            <i class="glyphicon glyphicon-edit" aria-hidden="true"></i>
                                        </button>
                                        <button id="deleteTreeBtn" type="button" class="btn btn-outline btn-default">
                                            <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>
                                        </button>*@
                                    <button id="refreshTreeBtn" type="button" class="btn btn-outline btn-default">
                                        <i class="glyphicon glyphicon-refresh" aria-hidden="true"></i>
                                    </button>

                                    <button id="selBtn" type="button" class="btn btn-info" title="选择城市">
                                        选择城市
                                    </button>
                                </div>
                            </div>

                            <div class="col-sm-6">
                                <div class="btn-group">

                                </div>
                            </div>
                        </div>

                        <div class="row row-lg ">
                            <div class="treeDiv">
                                <div id="tree" class="col-sm-12"></div>
                            </div>
                        </div>
                    </div>

                    @*<div class="col-sm-8">
                            <div class="row row-lg">
                                <div class="col-sm-12">
                                    <table id="table"></table>
                                </div>
                            </div>
                        </div>*@

                </div>

            </div>
        </div>
        @* 用来传递消息的隐藏域 *@
        <input id="handle_status" value="" hidden="hidden">
    </div>


    <!-- 全局js -->
    <script type="text/javascript" src="~/Scripts/jquery.min.js?v=2.1.4"></script>
    <script type="text/javascript" src="~/Scripts/bootstrap.min.js?v=3.3.6"></script>
    <!-- 自定义js -->
    <script type="text/javascript" src="~/Scripts/content.js?v=1.0.0"></script>
    <!-- Bootstrap table -->
    <script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script type="text/javascript" src="~/Scripts/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>

    <!-- layer javascript -->
    <script type="text/javascript" src="~/Scripts/plugins/layer/layer.min.js"></script>
    <!-- jsTree plugin javascript -->
    <script src="/Scripts/plugins/jsTree/jstree.min.js"></script>
    <script src="~/Scripts/common.js"></script>
    <script type="text/javascript">

        //var $table = $('#table');
        var $tree = $('#tree');
        var heiht = $.getUrlParam("height");
        heiht = heiht == null ? 150 : heiht;

        $(function () {
            //initTable();
            initTree();
        });

        //查询的参数
        //var queryParams = function (params) {
        //    var temp = {
        //        pageSize: params.limit,                             //行数
        //        pageIndex: (params.offset / params.limit) + 1,      //页码
        //        search: '',                       //查询内容
        //        treeId: $tree.getSelectNode() == undefined ? 0 : $tree.getSelectNode().id
        //    };
        //    return temp;
        //};
        //function initTable() {
        //    var columns = [
        //    {
        //        field: 'text',
        //        title: '菜单显示',
        //        align: 'center'
        //    }, {
        //        field: 'title',
        //        title: '窗口标题',
        //        align: 'center',
        //    }, {
        //        field: 'url',
        //        title: '地址',
        //        align: 'center',
        //    }];
        //    $('#table').initTable('/Menu/ContracListAsync', columns, heiht, queryParams, function (data) {
        //        if (data.total == 0) {
        //            $(".ibox-content").css("padding-bottom", "22px");
        //        } else {
        //            $(".ibox-content").css("padding-bottom", "4px");
        //        }
        //    });
        //}

        //初始化树数据
        function initTree() {
            $tree.initTree('/User/AreaIndexAsync', function () {
                //$table.bootstrapTable('refresh');
            });
            $(".treeDiv").height(getHeight() - 19);
        }

        //刷新树数据
        $('#refreshTreeBtn').click(function (e) {
            $tree.jstree("refresh");
        });

        //选择城市
        $('#selBtn').click(function (e) {

            if ($tree.getSelectNode().parents.length < 4) {
                layer.msg("请选择城市！", { icon: 5, time: 2000 });
                return;
            }

            var name = $tree.getSelectNode().text;
            var id = $tree.getSelectNode().id;

            //传值
            var body = parent.layer.getChildFrame('body', '@ViewData["layerindex"]');
            body.find('#CityName').val(name);
            body.find('#CityID').val(id);

            //关闭
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        });

        //打开树层
        //function openTreeLayer(type) {
        //    var title = "添加菜单";
        //    var url = "/Menu/Insert";
        //    parent.MenuTree_selectNode = $tree.getSelectNode();
        //    if (!isNaN(parseInt(type)) && parseInt(type) != 0) {
        //        title = "编辑菜单";
        //        url = "/Menu/Edit?id=" + type;
        //    }
        //    parent.layer.open({
        //        type: 2,
        //        title: title,
        //        shadeClose: false,
        //        shade: 0.4,
        //        area: ['500px', '400px'],
        //        content: url,
        //        end: function () {
        //            $tree.jstree("refresh");
        //        }
        //    });
        //}

        //新增树节点
        //$('#insertTreeBtn').click(function (e) {
        //    if ($tree.getSelectNode().parents.length >= 4) {
        //        layer.msg("请选择一个非末级节点！", { icon: 5, time: 2000 });
        //        return;
        //    }
        //    openTreeLayer(0);
        //});
        //修改树节点
        //$('#editTreeBtn').click(function (e) {
        //    if ($tree.getSelectNode().parents.length <= 1) {
        //        layer.msg("根节点不能编辑！", { icon: 5, time: 2000 });
        //        return;
        //    }
        //    openTreeLayer($tree.getSelectNode().id);
        //});
        //删除树节点
        //$('#deleteTreeBtn').click(function (e) {
        //    var selected = $tree.getSelectNode();
        //    if (selected == undefined) {
        //        layer.msg("请选择您要删除的数据！", { icon: 5, time: 2000 });
        //        return;
        //    }

        //    if (selected.parents.length <= 1) {
        //        layer.msg("根节点不能删除！", { icon: 5, time: 2000 });
        //        return;
        //    }

        //    layer.confirm('您确定要删除所选数据吗', {
        //        btn: ['是的', '取消'] //按钮
        //    }, function () {
        //        $.ajax({
        //            url: "/Menu/DeleteAsync",
        //            type: "post",
        //            dataType: "json",
        //            data: { id: selected.id },
        //            success: function (data) {
        //                var type = data.type;
        //                if (type == 1) {
        //                    layer.msg(data.content,
        //                        {
        //                            icon: 6, time: 2000
        //                        },
        //                        function () {
        //                            $tree.jstree(true).refresh();
        //                            refreshTable();
        //                        });
        //                } else {
        //                    layer.msg(data.content, { icon: 5, time: 2000 });
        //                }
        //            }
        //        });
        //    }, function () {
        //        return;
        //    });
        //});




        //刷新表格数据
        //var refreshTable = function () {
        //    $table.bootstrapTable('refresh');
        //}

        //获取表格高度
        function getHeight() {
            return $(window).height() - 150;
        }
        //重置表格高度
        //$(window).resize(function () {
        //    $table.bootstrapTable('resetView', {
        //        height: getHeight()
        //    });
        //    $(".treeDiv").height(getHeight() - 19);
        //});

        //刷新按钮
        //$('#refreshBtn').click(function (e) {
        //    refreshTable();
        //});

        //刷新按钮
        //$('#searchBtn').click(function (e) {
        //    $table.bootstrapTable('refresh');
        //});


        //function openLayer(id) {
        //    var title = "添加联系人";
        //    var url = "/EstateManagementCompany/InsertContract";
        //    parent.EstateManagementCompany_selectNode = $tree.getSelectNode();
        //    if (!isNaN(parseInt(id)) && parseInt(id) != 0) {
        //        title = "编辑联系人";
        //        url = "/EstateManagementCompany/EditContract?id=" + id;
        //    }
        //    parent.layer.open({
        //        type: 2,
        //        title: title,
        //        shadeClose: false,
        //        shade: 0.4,
        //        area: ['400px', '380px'],
        //        content: url,
        //        end: function () {
        //            refreshTable();
        //        }
        //    });
        //}

        //$('#insertBtn').click(function (e) {
        //    if ($tree.getSelectNode().parents.length != 3) {
        //        layer.msg("请选择一个三级节点！", { icon: 5, time: 2000 });
        //        return;
        //    }
        //    openLayer(0);
        //});
        //$('#editBtn').click(function (e) {
        //    var selected = $table.bootstrapTable('getSelections');
        //    if (selected.length > 1) {
        //        layer.msg("一次只能修改一条数据！", { icon: 5, time: 2000 });
        //        return;
        //    }

        //    if (selected.length == 0) {
        //        layer.msg("请选择您要修改的数据！", { icon: 5, time: 2000 });
        //        return;
        //    }
        //    openLayer(selected[0].id);
        //});

        //$('#deleteBtn').click(function (e) {
        //    var selected = $table.bootstrapTable('getSelections');
        //    if (selected.length == 0) {
        //        layer.msg("请选择您要删除的数据！", { icon: 5, time: 2000 });
        //        return;
        //    }
        //    var arr = [];
        //    for (var i = 0; i < selected.length; i++) {
        //        arr.push(selected[i].id);
        //    }
        //    var ids = arr.join(",");
        //    layer.confirm('您确定要删除所选数据吗', {
        //        btn: ['是的', '取消'] //按钮
        //    }, function () {
        //        $.ajax({
        //            url: "/EstateManagementCompany/DeleteContractAsync",
        //            type: "post",
        //            dataType: "json",
        //            data: { ids: ids },
        //            success: function (data) {
        //                var type = data.type;
        //                if (type == 1) {
        //                    layer.msg(data.content,
        //                        {
        //                            icon: 6, time: 2000
        //                        },
        //                        function () {
        //                            refreshTable();
        //                        });
        //                } else {
        //                    layer.msg(data.content, { icon: 5, time: 2000 });
        //                }
        //            }
        //        });
        //    }, function () {
        //        return;
        //    });
        //});

    </script>
</body>
</html>
